export default {
  mounted(el, binding) {
    // console.log(el, binding);
    const oSelectorInput = el.querySelector('.selector-input'),
          oSelectorMenu = el.querySelector('.selector-menu'),
          oInput = oSelectorInput.querySelector('input'),
          oPlaceholder = oSelectorInput.querySelector('label'),
          oIcon = oSelectorInput.querySelector('span');

    oInput.addEventListener('focus', function () {
      oPlaceholder.style.display = 'none';
      oIcon.className = 'iconfont icon-search';

      // 因为控制组件的消失和隐藏同时绑定 需要延迟进行 否则组件内部的绑定事件不会出发
      setTimeout(() => {
        oSelectorMenu.style.display = 'block';
      }, 200);
    }, false);

    oInput.addEventListener('blur', function () {
      oIcon.className = 'iconfont icon-arrow-down';

      setTimeout(() => {
        oSelectorMenu.style.display = 'none';
        
        if (this.value.length === 0) {
          oPlaceholder.style.display = 'block';
        }
      }, 200);
    }, false);
  },
  updated(el, binding) {
    // console.log(el, binding);
    
  },
}